angular.module("eve.controller", 
  [
  "eve.service",
  "ui.bootstrap"
  ])

//面包屑导航
.controller("BreadcrumbCtrl", ["$scope", "$location",
function($scope,$location) {
  $scope.navs = [
    {label:"首页",href:"#/"},
    {label:"工单",href:"#/order"},
    {label:"新建",active:true}
  ];
  
}])

// 侧边菜单
.controller("SideBarCtrl", ["$scope", "Menu",
function($scope, Menu) {
  


    $scope.menus = Menu.getMenus();

    $scope.goto = function(menu){
      $scope.menus.forEach(function (e){
        e.actived = false;
      });
      menu.actived = true;
    };
}])

// 顶部导航栏
.controller("NavCtrl", ["$scope", "$location", 
function($scope,$location) {
  $scope.logoff = function(){
    
    window.location.href = "/signin.html";
  };
}])

//Dashboard
.controller("DashboardCtrl", ["$scope","$rootScope", function($scope,$rootScope){
 
}])

//工单相关
.controller("OrderListCtrl", [
    "$scope","$location",  function($scope, $location) {

  $scope.orders = [];

  $scope.categories = [
    {label:"公网IP",category:"eip"},
    {label:"域名",category:"dns"},
    {label:"防火墙",category:"firewall"},
    {label:"虚拟主机",category:"vm"},
    {label:"磁盘空间",category:"disk"},
    {label:"负载均衡器",category:"lb"},
    {label:"堡垒机账号",category:"sysaccount"},
    {label:"数据库实例",category:"dbinstance"},
    {label:"数据库用户",category:"dbuser"}
  ];    
}])

.controller("OrderCreateCtrl", ["$scope", "$routeParams", "Form", function($scope, $routeParams, Form){

  var category = $routeParams.cate;
  $scope.tplName = "/tpl/form/" + category + ".tpl.html";
  $scope.category = category;
  $scope.order = {};

  switch (category){
    case "eip":
     
    $scope.order.eip = {
      isp: "any"
    }; 
    break;
  case "dns":
    

    $scope.order.dns = {
      parent: ".sina.com"
    };

    break;
  case "firewall":

    $scope.order.firewall = {
      rules:[]
    };

    $scope.addRule = function(){
      $scope.order.firewall.rules.push(
        { src:"",target:"",protocal:"TCP",port:"",remark:"new rule" });
    };  

    $scope.rmRule = function(r){
      angular.forEach($scope.order.firewall.rules,function(e,k){
        if(r == e){
          $scope.order.firewall.rules.splice(k,1);
        }
      });
    };

    break;
  case "vm":

    $scope.order.vm = {
        cpus:0,
        mem:1024,
        os:{
          name: "-1",
          lsb: "-1"
        },
        disks:[]
    };

    $scope.addDisk = function(){
      $scope.order.vm.disks.push(
        { name:"",type:"0",mount:"",fstype:"ext4",volume: 30,backup:"1" });
    };  

    $scope.rmDisk = function(d){
      angular.forEach($scope.order.vm.disks, function(e,k){
        if(d == e){
          $scope.order.vm.disks.splice(k,1);
        }
      });
    };


    break;
  case "disk":

    $scope.order.disk = {
      vm:"-1",
      disks:[]
    };

    $scope.addDisk = function(){
      $scope.order.disk.disks.push(
        { name:"",type:"0",mount:"",fstype:"ext4",volume:30 ,backup:"1" });
    };  

    $scope.rmDisk = function(d){
      angular.forEach($scope.order.disk.disks, function(e,k){
        if(d == e){
          $scope.order.disk.disks.splice(k,1);
        }
      });
    };

    break;
  case "lb":
    $scope.order.lb = {
      strategy:"0",
      rs:[]
    };

    $scope.addServer = function(){
      $scope.order.lb.rs.push(
        { address:"", priority:0});
    };  

    $scope.rmServer = function(d){
      angular.forEach($scope.order.lb.rs, function(e,k){
        if(d == e){
          $scope.order.lb.rs.splice(k,1);
        }
      });
    };

    break;
  case "sysaccount":

    $scope.order.sysaccount = {
      vm:"-1",
      root: "false"
    };    
    break;
  case "dbinstance":
    break;
  case "dbuser":
    break;
  default:
    
  }
}])

//账号相关
.controller("AccountCtrl", [
    "$scope","$location", function($scope,$location) {

   
}])

//反馈相关
.controller("FeedbackCtrl", [
    "$scope","$location", function($scope,$location) {

   
}])

//end
;



